﻿using System;
using System.Linq;
using Prepare.Domain;
using Prepare.Domain.Entities;

namespace Prepare.WebUI
{
    public partial class _TestUoW : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }

        private void BindGrid()
        {
			var r1 = UnitOfWork.GetRepository<Test>();
			var ds1 = r1.GetAll();

			var ds2 = UnitOfWork.GetRepository<Test>().GetAll();

			var ds3 = UnitOfWork.GetRepository<Account>().
                Find(a => a.UserName.StartsWith("P")).
                Select( a => new { Name = a.FirstName + " " + a.LastName, UserName = a.UserName, Password = a.Password } );

			var ds5 = UnitOfWork.GetRepository<Account>().Find(a => a.FirstName.StartsWith("p"), "StudentTests").
				Select(a => new { Name = a.FirstName, TestId = a.StudentTests.Count });

			var ds4 = AccountManager.GetTestAccounts();

			lstDragons.DataSource = ds5;
            lstDragons.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Test test = TestManager.CreateTest();
			UnitOfWork.Commit();

            BindGrid();
        }
    }
}
